package gui;

import javax.swing.JLabel;
import javax.swing.JPanel;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Hashtable;

import javax.swing.JLayeredPane;

import logic.Block;
import java.awt.Color;

public class BoardPanel extends JLayeredPane implements MouseListener,MouseMotionListener,Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -4480204877834115231L;
	/**
	 * 
	 */
	public final static int DEFAULT_LABEL_WIDTH  = 50;
	public final static int DEFAULT_LABEL_HEIGHT = 50;
	

	private static int 				_LabelWidth = DEFAULT_LABEL_WIDTH;
	private static int 				_LabelHeight= DEFAULT_LABEL_HEIGHT;
	private JLabel					_LabelShadow;
	private Hashtable<JLabel,Block>	_Blocks;

	/**
	 * Create the panel.
	 */
	public BoardPanel() {
		setOpaque(true);
		setBackground(Color.WHITE);
		setLayout(null);
	}
	
	public void addBlock( Block pBlock , int x , int y ){
		JLabel label = new JLabel();
		label.setBounds(x*_LabelWidth, y*_LabelHeight, _LabelWidth, _LabelHeight );
		label.setVisible(true);
		this.add(label);
		_Blocks.put(label, pBlock);
	}

	public void genTable(Graphics g){
		int colCount = getWidth()/_LabelWidth + 1;
		int rowCount = getHeight()/_LabelHeight + 1;
		for ( int row = 0 ; row < rowCount ; row++ ){
			g.drawLine( 0 , row*_LabelHeight , colCount*_LabelWidth , row*_LabelHeight );
		}
		for ( int col = 0 ; col < colCount ; col++ ){
			g.drawLine(col*_LabelWidth, 0, col*_LabelWidth, rowCount*_LabelHeight );
		}
	}
	
	public void paint(Graphics g){
		super.paint(g);
		genTable(g);
	}

	public static int getLabelWidth() {
		return _LabelWidth;
	}

	public static void setLabelWidth(int labelWidth) {
		_LabelWidth = labelWidth;
	}

	public static int getLabelHeight() {
		return _LabelHeight;
	}

	public static void setLabelHeight(int labelHeight) {
		_LabelHeight = labelHeight;
	}	
	
	public JLabel get_LabelShadow() {
		return _LabelShadow;
	}

	public void set_LabelShadow(JLabel _LabelShadow) {
		this._LabelShadow = _LabelShadow;
	}

	@Override
	public void mouseClicked(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseDragged(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseMoved(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	
}
